﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace FrbaCommerce.Gestion_de_Preguntas
{
    public partial class ListadoRespuestas : Form
    {
        
        private int user_id;

        public ListadoRespuestas(int user_id)
        {
            InitializeComponent();
            this.user_id = user_id;
        }

        private void ListadoPreguntas_Load(object sender, EventArgs e)
        {

        }

        private void buttonBuscar_Click(object sender, EventArgs e)
        {
            dataGridView1.Columns.Clear();

            SqlConnection con = Program.obtenerConexion();

            SqlDataAdapter buscar = new SqlDataAdapter("SELECT preg_id as 'ID', preg_descripcion as 'Descripción', preg_respuesta_desc as 'Respuesta'"
                + " FROM Monkey_Coders.Preguntas, Monkey_Coders.Publicaciones"
                + " WHERE preg_descripcion like '%" + textBoxDesc.Text + "%'"
                + " AND preg_publicacion_id = pub_cod"
                + " AND preg_respuesta_desc is not NULL"
                + " AND preg_usuario_id= " + user_id, con);

            SqlCommandBuilder commandBuilder = new SqlCommandBuilder(buscar);
            DataSet ds = new DataSet();
            buscar.Fill(ds);
            dataGridView1.ReadOnly = true;
            dataGridView1.DataSource = ds.Tables[0];
        }

    }
}
